/**
 * 商品管理API
 */

import request from '@/utils/request'

/**
 * 获取商品列表
 * @param params
 */
export function getGoodsList(params) {
  return request({
    url: 'admin/goods',
    method: 'get',
    loading: false,
    params
  })
}

/**
 * 修改商品搜索优先级
 * @param goods_id
 * @param priority
 */
export function modifyPriority(goods_id, priority) {
  return request({
    url: 'admin/goodssearch/priority',
    method: 'put',
    loading: false,
    params: { goods_id, priority }
  })
}

/**
 * 下架商品
 * @param goods_id 商品ID
 * @param reason 下架原因
 * @returns {*}
 */
export function underGoods(goods_id, reason) {
  return request({
    url: `admin/goods/${goods_id}/under`,
    method: 'put',
    data: { reason }
  })
}

/**
 * 上架商品
 * @param goods_id 商品ID
 * @returns {*}
 */
export function upGoods(goods_id) {
  return request({
    url: `admin/goods/${goods_id}/up`,
    method: 'put'
  })
}

/**
 * 获取待审核商品列表
 * @param params
 */
export function getAuditGoods(params) {
  params.is_auth = 0
  return request({
    url: `admin/goods`,
    method: 'get',
    loading: false,
    params
  })
}

/**
 * 审核商品
 * @param goods_id
 * @param params
 * @returns {*}
 */
export function auditGoods(goods_id, params) {
  return request({
    url: `admin/goods/${goods_id}/auth`,
    method: 'put',
    data: params
  })
}

/**
 * 商品索引生成
 */
export function initSearchIndex() {
  return request({
    url: 'admin/goods/search',
    method: 'get'
  })
}

/**
 * 获取商品设置
 */
export function getGoodsSettings() {
  return request({
    url: 'admin/goods/settings',
    method: 'get'
  })
}

/**
 * 修改商品设置
 * @param params
 */
export function editGoodsSettings(params) {
  return request({
    url: 'admin/goods/settings',
    method: 'post',
    data: params
  })
}

/**
 * 复制商品
 * @param params
 */
export function copyGoods(params) {
  return request({
    url: '/admin/goods/copyGoods',
    method: 'post',
    data: params
  })
}

/**
 * excel表商品
 * @param params
 */
export function importGoods(params) {
  return request({
    url: '/admin/excel/importGoods',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: params
  })
}

/**
 * excel表sku
 * @param params
 */
export function importGoodsSku(params) {
  return request({
    url: '/admin/excel/importGoodsSku',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: params
  })
}
/**
 * 导出商品明细
 * @param params
 */
export function exportGoodsSku(params) {
  return request({
    responseType: 'blob',
    url: 'admin/excel/exportGoodsSku',
    method: 'get',
    timeout: 0,
    params
  })
}
/**
 * 批量下架商品
 * @param params
 */
export function batchGoodsUnder(params) {
  return request({
    url: `/admin/goods/batch/under/${params}`,
    method: 'put'
  })
}
/**
 * 批量上架商品
 * @param params
 */
export function batchGoodsUp(params) {
  return request({
    url: `/admin/goods/batch/up/${params}`,
    method: 'put'
  })
}
/**
 * 批量设置补贴
 * @param params
 */
export function batchEditGoods(goods_ids, params) {
  return request({
    url: `/admin/distribution/goods/batchEditGoods/${goods_ids}`,
    method: 'put',
    data: params
  })
}

